/*
    Author: Christopher Diggins
	    License: MIT Licence 1.0
    Website: http://www.cdiggins.com
*/

#include "heron.hpp"

void Usage() {
	printf("Usage:\ncvml.exe <infolder> <outfolder> <infile> <outfile> [options]\n");
	printf("Options:\n");
	printf("-o0 -o1 -o2 -o3 -oX\n");
	exit(1);
}

/*
void TestLua() {
	lls::LuaMachine L;
	//L.Eval("io.write(\"42\")");
	L.Eval("function f() g() end function g() io.write(\"42\") end f()");
}
*/

int main(int argc, char** argv)
{	
	if (argc < 5) {
		Usage();
	}
	
	sInFolder = argv[1];
	sOutFolder = argv[2];
	sInFileName = argv[3];	
	sOutFileName = argv[4];
	sInFile = sInFolder + "\\" + sInFileName;
	sOutFile = sOutFolder + "\\" + sOutFileName;

	for (int i=5; i < argc; i += 1) {
		if (strcmp(argv[i], "-o0") == 0) {	
			// Turns off even the most basic optimization
			bCompaction = false;
		}
		else if (strcmp(argv[i], "-o1") == 0) {
			// default optimizations
		}
		else if (strcmp(argv[i], "-o2") == 0) {
			bGenerateSubs = true;
			bMakeTailCalls = false;
			bInline = false;
		}
		else if (strcmp(argv[i], "-o3") == 0) {
			bGenerateSubs = false;
			bMakeTailCalls = true;
			bInline = false;
		}
		else if (strcmp(argv[i], "-o4") == 0) {
			bGenerateSubs = false;
			bMakeTailCalls = false;
			bInline = true;
		}
		else if (strcmp(argv[i], "-oX") == 0) {
			bGenerateSubs = true;
			bMakeTailCalls = true;
			bInline = true;
		}
		else {
			Usage();
		}
	}

	printf("Options: ");
	for (int i=1; i < argc; ++i) {
		printf("%s ", argv[i]);
	}
	printf("\n");
	Compiler c;
	if (!c.Compile()) {
		return 1;
	}
	if (bRunMain) {
		printf("Running program:\n");
		c.Run();
	}
	return 0;
}    
